package Picture.Sevlect;

import Picture.entiy.Picture;
import Picture.service.PictureService;
import Picture.service.impl.PictureSerImpl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

/**
 * @author chenle
 * @version 1.0
 * @date 2023/10/13 14:17
 */
@WebServlet("/SumServlet")
public class SumServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        PictureService service=new PictureSerImpl();
//        service.getList();

        Picture picture=new Picture();
        List<Double> salesList = new ArrayList<>();


        picture.getNumber();
        String[] dataArr = new String[10];
        String[] sumArr = new String[10];
        double init = 100D;
        // 最近七天
        Calendar calendar = Calendar.getInstance();
        for (int i = 1; i < 10; i++) {
            calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -i);
            dataArr[i-1] = calendar.get(Calendar.YEAR) + "-" + (calendar.get(Calendar.MONTH) + 1) + "-" + calendar.get(Calendar.DAY_OF_MONTH);
            String beginTime=dataArr[i-1]+" 00:00:00" ;
            String endTime=dataArr[i-1]+" 23:59:59" ;
            sumArr[i-1] = service.sumAmout(beginTime,endTime)+"";
        }
        Map<Object, Object> resMap = new HashMap<>();
        resMap.put("dataArr", dataArr);
        resMap.put("sumArr", sumArr);
        PrintWriter out = response.getWriter();
        out.print(JSONObject.toJSONString(resMap));
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
